module.exports = () => {
    return async function auth(ctx, next) {
        // 取出来authorization
        // 截取出来 token
        // 校验token 
        const { authorization } = ctx.request.header;
        if (authorization) {
            try {
                const token = authorization.split(' ')[1]
                const jwt = require('jsonwebtoken')
                jwt.verify(token, ctx.app.config.keys)
                await next()
            } catch (err) {
                ctx.status = 401;
                ctx.body = {
                    success: false,
                    message: "解析失败" + err.message
                }
            }
        } else {
            ctx.status = 401;
            ctx.body = {
                success: false,
                message: "请先登录"
            }
        }
    }
}